package com.lb.reward;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class TestInstance {

    //初始化各奖品设置
    private ArrayList<Reward> rewards = new ArrayList() {{
        add(new Reward("智能锁", 0.0, 0));
        add(new Reward("京东卡", 0.05, 10));
        add(new Reward("不粘锅", 0.25, 20));
        add(new Reward("洗衣液", 0.3, 30));
        add(new Reward("旅游卡", 0.4, -1));
    }};

    // 初始化抽奖获得队列
    private Map<String, String> rewardList = new HashMap();

    public void getRewards() {
        System.out.println(rewardList);
    }

    public void doReward() {

        Random rand = new Random();
        int randNum = rand.nextInt(100) + 1;

        String uid = Thread.currentThread().getName() + "/" + randNum;
        int tag = 0;
        for (Reward item : rewards) {
            tag += item.getRate() * 100;
            if (randNum <= tag) {
                item.getRewardUidList().add(uid);
                rewardList.put(uid, item.getRewardByUid(uid));
                break;
            }
        }
    }
}